<template>
	<view class="login">
		<view class="time">
			<text class="timeTxt" @click="cli_t">跳过{{time}}s</text>
		</view>
		<view class="logo">
			<image class="img" src="https://www.zzzsyh.com/applets/agent/agent/logo.png" mode=""></image>
		</view>
		<view class="title">
			主事丫环
		</view>
		<view class="content">
			全国家庭服务平台
		</view>
		<!-- <view class="btn">
			<button v-if="show_check" class="btn-btn" type="default" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信登录</button>
			<button v-else @click="cli_checkNo" class="btn-btn">微信登录</button>
		</view>
		<view class="check">
			<image @click="cli_check" v-if="show_check" src="../../static/common/check_ok.png" mode=""></image>
			<image @click="cli_check" v-else src="../../static/common/check_no.png" mode=""></image>
			<text class="check1">我已同意阅读</text>
			<text class="check2" @click="cli_privacy">《隐私政策》</text>
		</view> -->
	</view>
</template>

<script>
	// import allapi from '../../api/index.js'
	var timea;
	export default {
		props: {
			login: ''
		},
		data() {
			return {
				show_check: true,
				code: '',
				encryptDataB64: '',
				ivB64: '',
				time: '3'
			}
		},
		mounted() {
			// this.getLogin()
			this.changeTime()
		},
		methods: {
			// 时间改变
			changeTime() {
				timea = setInterval(() => {
					if (this.time > 0) {
						this.time--
					} else {
						console.log('qutama ');
						this.time = 0
						clearInterval(timea)
						this.cli_tg()
					}
				}, 1000)
			},
			cli_t() {
				// this.time = 0
				clearInterval(timea)
				this.cli_tg()
			},
			// 点击跳过
			cli_tg() {
				uni.getStorage({
					key: 'agentId',
					success: function(res) {
						console.log(res, '获取agentId');
						uni.switchTab({
							url: '/pages/index/index'
						});
					},
					fail: (err) => {
						console.log(err);
						uni.getStorage({
							key: 'id_factory',
							success: function(res) {
								console.log(res, '获取id_factory');
								uni.redirectTo({
									url: '/pages/manufacturers/order/order'
								});
							},
							fail: (errr) => {
								console.log(errr);
								uni.redirectTo({
									url: '/pages/login/login'
								})
							}
						});
					}
				});
			},
			// 点击是否阅读隐私政策
			getPhoneNumber(e) {
				console.log('获取微信授权啊a', e);
				let code = this.code
				let _that = this
				uni.request({
					url: allapi.appletsLoginPhone +
						`code=${code}&encryptDataB64=${e.detail.encryptedData}&ivB64=${e.detail.iv}`, //仅为示例，并非真实接口地址。
					success: (res) => {
						console.log(res.data);
						let dat = res.data.data
						uni.setStorageSync('userId', dat.id);
						uni.setStorageSync('phone', dat.phone);
						uni.setStorageSync('session_key', dat.session_key);
						uni.setStorageSync('openid', dat.openid);
						// _that.props.login = false
						// 传值给父组件
						_that.$emit('children', false)

					},
					fail(err) {
						wx.showToast({
							title: '出错了', //弹框内容
							icon: 'success', //弹框模式
							duration: 2000 //弹框显示时间
						})
					}
				});
			},
			// 登录
			getLogin() {
				let _that = this
				wx.checkSession({
					success() {
						//session_key 未过期，并且在本生命周期一直有效
						console.log('login未过期');
						wx.login({ //重新登录
							success(res) {
								console.log('登录信息', res)
								console.log(res.code);
								_that.code = res.code
							}
						})
					},
					fail() {
						// session_key 已经失效，需要重新执行登录流程
						wx.login({ //重新登录
							success(res) {
								console.log('登录信息', res)
								console.log(res.code);
								_that.code = res.code
							}
						})
					}
				})
			},
			// 点击切换是否阅读隐私
			cli_check() {
				this.show_check = !this.show_check
			},
			// 没有勾选隐私政策
			cli_checkNo() {
				uni.showToast({
					title: '请先勾选隐私政策',
					icon: 'none'
				})
			},
			// 跳转隐私
			cli_privacy() {
				uni.navigateTo({
					url: '/pages/aggrement/privacy/privacy'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.login {
		width: 100%;
		height: 100%;
		position: fixed;
		background: #FFFFFF;
		left: 0;
		top: 0;
		z-index: 666;

		.time {
			display: flex;
			justify-content: flex-end;
			margin-top: 240rpx;
		}

		.timeTxt {
			background: #CCCCCC;
			padding: 5rpx 10rpx;
			font-size: 28rpx;
			margin-right: 40rpx;
			border-radius: 8rpx;
			letter-spacing: 3rpx;
			color: #FFF3DD;
		}

		.logo {
			display: flex;
			justify-content: center;
			margin-top: 30%;

			.img {
				width: 240rpx;
				height: 240rpx;
			}
		}

		.title {
			font-size: 42rpx;
			color: #121212;
			line-height: 58rpx;
			text-align: center;
			margin-top: 10%;
		}

		.content {
			font-weight: 400;
			color: #666666;
			font-size: 28rpx;
			line-height: 40rpx;
			margin-top: 16rpx;
			text-align: center;
		}

		.btn {
			height: 80rpx;
			background: #28CD50;
			border-radius: 48px;
			margin: 0 64rpx;
			margin-top: 84rpx;
			text-align: center;
			line-height: 80rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #FFFFFF;

			.btn-btn {
				height: 80rpx;
				background: #28CD50;
				border-radius: 48px;
				margin: 0 64rpx;
				margin-top: 84rpx;
				text-align: center;
				line-height: 80rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #FFFFFF;
			}
		}

		.check {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 88rpx;
			font-size: 24rpx;
			font-weight: 400;
			color: #999999;

			image {
				width: 40rpx;
				height: 40rpx;
			}

			.check1 {
				margin-left: 18rpx;
			}

			.check2 {
				color: #28CD50;
			}
		}
	}
</style>
